package com.example.lp.lpuicore.paint.model;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;

import com.example.lp.lpuicore.R;

/**
 * Author by lp,on 2021/6/17/017,14:30.
 */
public class BitmapRendering implements IPaintModel {
    @Override
    public void draw(Canvas canvas, Paint paint) {
        /**
         * 位图渲染，BitmapShader(@NonNull Bitmap bitmap, @NonNull TileMode tileX, @NonNull TileMode tileY)
         * Bitmap:构造shader使用的bitmap
         * tileX：X轴方向的TileMode
         * tileY:Y轴方向的TileMode
         REPEAT, 绘制区域超过渲染区域的部分，重复排版
         CLAMP， 绘制区域超过渲染区域的部分，会以最后一个像素拉伸排版
         MIRROR, 绘制区域超过渲染区域的部分，镜像翻转排版
         */
        Bitmap mBitmap= BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.testface);
        BitmapShader    mShader = new BitmapShader(mBitmap, Shader.TileMode.REPEAT, Shader.TileMode.MIRROR);
        paint.setShader(mShader);
        canvas.drawRect(0, 0, 300, 300, paint);
    }
}
